#ifndef SYSTEM_H_
#define SYSTEM_H_

#include "cpu/io.h"
#include "lpc213x.h"
#include "delay.h"

//#define USE_SOFT_SPI_FOR_LCD
#define USE_HARD_SPI_FOR_LCD

// SSPCR0 Bit-Definitions
#define SPI_CPOL 6
// SSPCR1 Bit-Defintions
#define SSP_SSE 1
#define SPI_SCR 8
#define SSP_MSR 2
// SSPSR  Bit-Definitions
#define SSP_TNF     1
#define SSP_RNE     2
#define SSP_BSY		4

// NOKIA LCD PINs
#define LCD_CS    			(1<<7)
#define LCD_MOSI    		(1<<6)
#define LCD_RESET   		(1<<5)
#define LCD_SCK   			(1<<4)

#define LCD_DIR				IODIR0
#define LCD_CLR				IOCLR0
#define LCD_SET				IOSET0

#define SSP_SCK_PIN 		17 /* Clock P0.17 out */
#define SSP_MISO_PIN 		18 /* used for rest. p0.18 out */
#define SSP_MOSI_PIN 		19 /* to lcd P0.19 out */
#define SSP_SS_PIN 			20 /* to lcd. P0.20 out */

#define SPI_PINSEL 			PINSEL0
#define SPI_SCK_FUNCBIT 	8
#define SPI_MISO_FUNCBIT 	10
#define SPI_MOSI_FUNCBIT 	12
#define SPI_SS_FUNCBIT 		14
#define SPI_DATABITS 		9

/* System configuration: Fosc, Fcclk, Fcco, Fpclk must be defined */
/* Crystal frequency,10MHz~25MHz should be the same as actual status. */
#define Fosc	10000000

/* System frequency,should be (1~32)multiples of Fosc,and should be equal or
 less than 60MHz. */
#define Fcclk	(Fosc * 6)

/* CCO frequency,should be 2/4/8/16 multiples of Fcclk, ranged from 156MHz to
 320MHz. */
#define Fcco	(Fcclk * 4)

/* VPB clock frequency , must be 1/2/4 multiples of (Fcclk / 4). */
#define Fpclk	(Fcclk / 4) * 4

void feed(void);

void system_Init(void);

#endif /*SYSTEM_H_*/
